<?php
/**
 * @version		$Id: view.html.php 17130 2010-05-17 05:52:36Z eddieajau $
 * @copyright	Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */

// No direct access
defined('_JEXEC') or die;

jimport('joomla.application.component.view');

/**
 * @package		Joomla.Administrator
 * @subpackage	com_content
 */
class AjaxWhoisViewExtensions extends JView
{
	protected $items;
	protected $pagination;
	protected $state;

	/**
	 * Display the view
	 */
	public function display($tpl = null)
	{
		$this->items		= $this->get('Items');
		$this->pagination	= $this->get('Pagination');
		$this->state		= $this->get('State');

		// Check for errors.
		if (count($errors = $this->get('Errors'))) {
			JError::raiseError(500, implode("\n", $errors));
			return false;
		}

		$this->addToolbar();
		parent::display($tpl);
	}

	/**
	 * Method to make filter Lists
	 *
	 * @return      boolean true of false in case of failure
	 */
	public function lists() {
		
		// Create a new query object.         
		$db =& JFactory::getDBO();
		
		$filter_continent = $this->state->get('filter.continent');
		$filter_country   = $this->state->get('filter.country');
		$filter_which 	  = $this->state->get('filter.which');
		
		$cont = array();
		//Make a list of continents
		$query = $db->getQuery(true);
		$query->select("DISTINCT(continent) AS continent, continent AS value");
		$query->from("#__aw_ext");
		$query->where("continent!=''");
		$query->order("continent");
		$cont[] = JHTML::_('select.option', '', '- '.JText::_('Select Continent').' -', 'value', 'continent');
		$cont[] = JHTML::_('select.option', 'none', '- '.JText::_('None').' -', 'value', 'continent');
		$db->setQuery($query);
		$cont = array_merge($cont, $db->loadObjectList());
		$lists['continent'] = JHTML::_('select.genericlist',  
							  $cont, 'filter_continent', 'class="inputbox" size="1" onchange="this.form.submit()"', 
							  'value', 'continent', $filter_continent);

		$cnt = array();
		//Make a list of country
		$query = $db->getQuery(true);
		$query->select("DISTINCT(country) AS country, country AS value");
		$query->from("#__aw_ext");
		$query->where("country!=''");
		$query->order("country");
		$cnt[] = JHTML::_('select.option', '', '- '.JText::_('Select Country').' -', 'value', 'country');
		$cnt[] = JHTML::_('select.option', 'none', '- '.JText::_('None').' -', 'value', 'country');
		$db->setQuery($query);
		$cntry = array_merge($cnt, $db->loadObjectList());
		$lists['country'] = JHTML::_('select.genericlist',  
							$cntry, 'filter_country', 'class="inputbox" size="1" onchange="this.form.submit()"', 
							'value', 'country', $filter_country);
		
		$which   = array();
		$which[] = JHTML::_( "select.option", '0', JText::_( "All Extensions" ) );
		$which[] = JHTML::_( "select.option", '1', JText::_( "Both In Component and In Module" ) );
		$which[] = JHTML::_( "select.option", '2', JText::_( "Only In Component" ) );
		$which[] = JHTML::_( "select.option", '3', JText::_( "Only In Module" ) );
	
		$lists['which']  = JHTML::_( 'select.genericList', 
						 $which, 'filter_which', 'class="inputbox" size="1" onchange="document.adminForm.submit();"', 
						 'value', 'text', $filter_which );
	
		return $lists;
		
	}
	
	/**
	 * Setting the toolbar
	 */
	protected function addToolBar() {
		
		$state	= $this->get('State');
		
		JToolBarHelper::title(JText::_('com_ajaxwhois_Extension_Manager'), 'extensions');
		JToolBarHelper::addNewX('extension.add');
		JToolBarHelper::editListX('extension.edit');
		JToolBarHelper::deleteListX('com_ajaxwhois_Extensions_Are_you_sure_you_want_to_delete_these_extensions', 'extensions.remove');
		
	}
}
